<?php

namespace App\Console\Commands;

use App\Models\Articles;
use Illuminate\Console\Command;

class ReplaceStr extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:replace_str';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Replace api string like "\n"';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info('start replace the datasets');
        $articles = Articles::all();
        $articles->each(function ($value){
            $name = $value->type->title;
            $array = ['生肖分析', '夫妻宫分析', '日主性格分析'];
            if (in_array($name, $array)){
                $res = str_replace('<br />', '<br/>', $value->value);
                $value->value = $res;
                $value->save();
            }
        });
        $this->info('completed!');
    }
}
